﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlueFlyPhone
{


    public enum DisplayModeEnum
    {
        Metric,
        Imperial,
        MetricVarioHeightInfeet,
    }

    public interface IUnitConverter
    {

        string DisplayUnit { get; }

        double ConvertToCalculationUnits(double value);

        string ConvertToDisplayUnits(double value, int precision);
    }


    public class UserPersistableSettings
    {

        public static DisplayModeEnum DisplayMode
        {
            get { return DisplayModeEnum.Metric; }
        }

    }


    public class UnitConverterService
    {


        static DisplayModeEnum displayMode;
        
        
        public static DisplayModeEnum DisplayMode
        {
            get { return displayMode; }

            set
            {
                if (displayMode != value)
                {
                    displayMode = value;
                    setUpConverters(displayMode);
                }
            }

        }

        private static void setUpConverters(DisplayModeEnum displayMode)
        {

            switch (displayMode)
            {
                case DisplayModeEnum.MetricVarioHeightInfeet:

                    AltitudeConverter = new FeetAltitudeUnitConverter();
                    PressureConverter = new PressureUnitConverter();
                    VarioConverter = new VarioUnitConverter();

                    break;
                case DisplayModeEnum.Metric:

                    AltitudeConverter = new AltitudeUnitConverter();
                    PressureConverter = new PressureUnitConverter();
                    VarioConverter = new VarioUnitConverter();

                    break;
                case DisplayModeEnum.Imperial:

                    AltitudeConverter = new FeetAltitudeUnitConverter();
                    PressureConverter = new PressureUnitConverter();
                    VarioConverter = new FtPerMinVarioUnitConverter();
                    
                    break;

            }

            
        }

        static UnitConverterService()
        {
            DisplayMode = UserPersistableSettings.DisplayMode;
            setUpConverters(DisplayMode);

        }


        public static IUnitConverter AltitudeConverter
        {
            get;
            private set;
        }

        public static IUnitConverter PressureConverter
        {
            get;
            private set;

        }


        public static IUnitConverter VarioConverter
        {
            get;
            private set;

        }

    }


}
